/**
 * 
 */
package xj.toolkit.util;

import static org.junit.Assert.*;

import org.apache.commons.beanutils.PropertyUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import xj.toolkit.util.PojoAsMapAdapter;

/**
 * @author Marvin.Ma
 *
 */
public class PojoAsMapAdapterTestCase {

	public static class User {
		private String name;
		private int age;

		/**
		 * @return the name
		 */
		public String getName() {
			return name;
		}

		/**
		 * @param name
		 *            the name to set
		 */
		public void setName(String name) {
			this.name = name;
		}

		/**
		 * @return the age
		 */
		public int getAge() {
			return age;
		}

		/**
		 * @param age
		 *            the age to set
		 */
		public void setAge(int age) {
			this.age = age;
		}

	}

	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testPropertyUtilsAndPojoAsMapAdapter() throws Exception {
		User user = new User();

		PojoAsMapAdapter bean = new PojoAsMapAdapter(user, true);

		assertNull(PropertyUtils.getProperty(bean, "name"));

		user.setName("marvin");

		assertEquals(PropertyUtils.getProperty(bean, "name"), "marvin");

		assertEquals(PropertyUtils.getProperty(bean, "age"), 0);

		user.setAge(34);

		assertEquals(PropertyUtils.getProperty(bean, "age"), 34);
	}
}
